package day05;

//数组的演示
public class ArrayDemo {
    public static void main(String[] args) {
        //声明整型数组a，包含5个元素，每个元素都是int型，默认值为0
        int a[] = new int[5];

        //声明浮点型数组d，包含10个元素，每个元素都是double型，默认值为0.0
        double d[] = new double[10];

        //声明布尔型数组b，包含26个元素，每个元素都是布尔型，默认值为false
        boolean[] b = new boolean[26];

        int[] arr1 = new int[3];

        int[] arr2 = {2, 5, 8};
        int[] arr3 = new int[]{2, 5, 8};

        int[] arr4;
        //arr4 = {2, 5, 8};//编译错误，此方式只能声明同时初始化
        arr4 = new int[]{2, 5, 8};
        //System.out.println(arr4.length);

        //数组的访问
/*        int arr[] = new int[3];
        System.out.println("数组的长度为：" + arr.length);
        System.out.println("第1个元素的值为：" + arr[0]);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
        System.out.println(arr[2]);//输出最后一个元素的值
        System.out.println(arr[arr.length - 1]);
*/
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = 100;
            System.out.println(arr[i]);
            System.out.println("---------------------------------------");
        }

        int[] as = new int[10];
        for (int i = 0; i < arr.length; i++) {
            as[i] = (int) (Math.random() * 100);
            System.out.println(as[i]);
        }


    }
}
